using HCManage.Api.Models;
using HCManage.IBll;
using HCManage.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace HCManage.Api.Controllers.Settings
{
    [Route("api/[controller]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        #region 模块

        private readonly ISysUserBll userBll;

        private DataResultModel dataResult = new DataResultModel();

        #endregion

        #region 构造函数

        public UsersController(ISysUserBll user_bll)
        {
            this.userBll = user_bll;
        }

        #endregion

        [HttpGet]
        public JsonResult List(string user_name, int page = 1, int page_size = 30)
        {
            Tuple<List<sys_user>, int> result = userBll.List("", user_name, page, page_size);
            dataResult.success = true;
            dataResult.data = result.Item1.Select(p => new
            {
                p.user_no,
                p.user_name,
                p.user_sex,
                p.user_mobile,
                p.user_email
            });
            dataResult.total = result.Item2;
            return new JsonResult(dataResult);
        }
    }
}
